package jdk.functionclass;

import jdk.entity.UserEntity;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * Consumer<T>
 * 代表了接受一个输入参数并且无返回的操作
 * @author songyafei
 */
public class ConsumerFunction {

    public static void main(String[] args) {
        List<String> stringList = new ArrayList<>();
        stringList.add("zhangsan");
        //模拟设置uuid,做一些处理
        handleList("103938448",s-> {
            stringList.add(s);
        },s1-> {
            //经过步骤1后再次拿到uuid执行后续操作
            System.out.println("模拟更新用户余额操作");
            Boolean state  = true;
            if(state){
                System.out.println("执行用户余额更新完成，记录用户操作号为{}"+s1+ LocalDate.now().toString());
            }
        });
        System.out.println("存储用户信息"+stringList.toString());

        processCustomer(1,(UserEntity e) -> System.out.println(e.toString()));
    }

    public static void handleList(String str,
                                  Consumer<String> consumer1,
                                  Consumer<String> consumer2){
        consumer1.andThen(consumer2).accept(str);
    }


    public static void handleList(String str,
                                  Consumer<String> consumer1){
        consumer1.accept(str);
    }


    public static void processCustomer(int id, Consumer<UserEntity> userEntityConsumer){
        //模拟业务逻辑
        UserEntity u2 = new UserEntity();
        u2.setAge(22);
        u2.setUserId(2L);
        u2.setCreatedDate(LocalDate.of(2011,01,20));
        u2.setName("刘乐");
        userEntityConsumer.accept(u2);
    }
}
